package com.example.wanandroid.app;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.example.wanandroid.Constants;
import com.example.wanandroid.core.dao.DaoMaster;
import com.example.wanandroid.core.dao.DaoSession;

public class WanAndroidApp extends Application {

    private static final String TAG = "WanAndroidApp";

    private static WanAndroidApp instance;

    private DaoSession mDaoSession;


    public static synchronized WanAndroidApp getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "wanandroid app onCreate: ---------------------" );
        initGreenDao();
        instance = this;
        Log.i(TAG, "onCreate: " + mDaoSession);
    }

    private void initGreenDao() {
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(this, Constants.DB_NAME);
        SQLiteDatabase database = devOpenHelper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(database);
        mDaoSession = daoMaster.newSession();
        Log.i(TAG, "initGreenDao: --------" + mDaoSession);
    }

    public DaoSession getDaoSession() {
        Log.i(TAG, "getDaoSession: --------------" + mDaoSession);
        return mDaoSession;
    }

}
